package com.swh.tetris;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class EnemyPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	
	public EnemyPanel() {
		this.setBackground(Color.darkGray);
	}
	
	public void refreshPanel() {
		repaint();
	}
	
	private void drawShape(Graphics g) {
		Shape shape=Config.enemyShape[3];
		if(shape==null) return;
		int shapeSize=Config.SHAPE_SIZE;
//		System.out.println("drawShape");
		int[][] arr=shape.getArray();
		int[] position=shape.getPositon();
		int x=position[0];
		int y=position[1];
		Color color=shape.getColor();
		g.setColor(color);
		for(int i=0;i<arr.length;i++){
			for(int j=0;j<arr[i].length;j++){
				if(arr[i][j]==1){
					g.fill3DRect((x+j)*shapeSize, (y+i)*shapeSize, shapeSize, shapeSize, true);
				}
			}
		}
	}
	
	private void drawContainer(Graphics g) {
		int[][] container=Config.enemyContainer;
		int shapeSize=Config.SHAPE_SIZE;
		Color color=null;
		for(int i=0;i<container.length;i++){
			for(int j=0;j<container[i].length;j++){
				if(container[i][j]!=0){
					color=new Color(container[i][j]);
					g.setColor(color);
					g.fill3DRect(j*shapeSize, i*shapeSize, shapeSize,shapeSize, true);
				}
			}
		}
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		drawShape(g);
		drawContainer(g);
	}

}
